﻿package  {
	import flash.display.MovieClip;
	import flash.events.*;
	import com.greensock.TimelineMax;
	import com.greensock.TweenMax;
	import flash.geom.ColorTransform;
	import flash.sampler.NewObjectSample;
	import fl.motion.Color;
	import flash.display.Shape;
	import flash.display.SimpleButton;
	import flash.text.TextField;
	import flash.utils.Timer;
	import flash.utils.getTimer;
	
	public class ControllerReels extends MovieClip {
		
		public static var instance:ControllerReels;
		//ui contents;
		public var btn_spin:MovieClip;
		public var btn_lines_up:MovieClip;
		public var btn_lines_down:MovieClip;
		public var btn_lines_max:MovieClip;
		
		public var reelBoxes:MovieClip;
		public var reelAnims:MovieClip;
		//work contents;
		
		public var boxesArray:Array;
		public var holesArray:Array;
		public var animsArray:Array;
		public var sublineArray:Array;
		public var linesArray:Array;
		public var wheelArray:Array;
		
		public var winsArray:Array;
		
		public var winTimeline:TimelineMax;
		public var winAnimCurrent:int;
		
		
		
		public var wheels_move:int;
		/*
		[line, indexes]
		line = 0. anim just boxes;
		line > 9. anim line, anim subline boxes, anims;
		*/
		
		
		
		//line1-9; {s1-full-line{s1,s2,..s5},s2 - disabled, s3-enabled}
		//sub{1-9} - full-line{s1}
		
		
		public var playNumbers:Array;
		
		
		
		
		
		public var gameFreeCount:int = -1;
		
		
		
		
		
		
		
		
		
		
		
		
		//PLAYER INFO
		public var player_balance:Number = 0;
		public var player_lines:int = 1;
		public var player_bet:Number = 1;
		public var player_win:Number = 0;
		
		//WIN ANIMATION VARS
		private var anim_explain_current:int;
		private var anim_explain_twm:TweenMax;
		
		
		
		public var anim_lines_arr:Array;
		public var anim_lines_twm:TweenMax;
		
		
		//BUTTONS
		public var bt_pay:XButton;
		public var bt_lines_prev:XButton;
		public var bt_lines_next:XButton;
		public var bt_bet_prev:XButton;
		public var bt_bet_next:XButton;
		public var bt_max:XButton;
		public var bt_spin:XButton;
		//UI
		public var logo_main:MovieClip;
		public var logo_free:MovieClip;
		
		public var recalc_timer:Timer;
		public var recalc_balance:Number;
		public var recalc_start:int;
		public var recalc_amount:Number;
		public var recalc_time:int;
		public var recalc_b:Boolean;
		public var recalc_w:Boolean;
		
		//TEXT
		public var tx_balance:TextField;
		public var tx_lines:TextField;
		public var tx_bet_amount:TextField;
		public var tx_bet_total:TextField;
		public var tx_win:TextField;
		
		//NETWORK:
		public var net_main:Network;
		public var net_free:Network;
		
		//SOUNDS: 
		public var sn_win:XSound;
		public var sn_wheels1:XSound;
		public var sn_wheels2:XSound;
		public var sn_wheel_stop:XSound;
		public var sn_up:XSound;
		public var sn_down:XSound;
		
		//VARIABLES
		public var currentGameFree:Boolean = false;
		public var currentGameWheels:int = 0;
		
		//FREE GAME
		public var inOnFree:Boolean;
		public var freeWinSumm:Number;
		public var freeSpinsCount:int;
		public var freeResultTable:MovieClip;
		
		
		
		public function ControllerReels() {
			super();
			ControllerReels.instance = this;
			// constructor code
			
			//Dev: Установка линий для начального отображения. Перенести в загрузчик init;
			this.playNumbers = new Array();
			for(var i=0;i<15;i++)
			{
				this.playNumbers.push(Helper.rand(1,12));
			}
			//TMP: initGameAfter ON_STAGE_EVENT;
			this.addEventListener(Event.ADDED_TO_STAGE, this.hOnStage);
		}
		
		//ON_STAGE_EVENT
		private function hOnStage(e:Event):void
		{
			this.removeEventListener(Event.ADDED_TO_STAGE, this.hOnStage);
			this.initSounds();
			this.initController();
			this.initUI();
			this.initButtons();
			//TODO: initTexts();
			this.initNetwork();
		}
		
		//INITIALIZERS
		private function initSounds():void
		{
			this.sn_win = new sndWin();
			this.sn_wheels1 = new sndWheelNormal();
			this.sn_wheels2 = new sndWheelFast();
			this.sn_up = new sndValueUp();
			this.sn_down = new sndValueDown();
			this.sn_wheel_stop = new sndWheelStop();
		}
		
		private function initUI():void
		{
			this.uiShowLogoMain();
			this.hideAllBoxes();
			this.hideAllSublines();
			this.showSelectedLines();
			this.updateUI();
			
			this.recalc_timer = new Timer(32);
			this.recalc_timer.addEventListener(TimerEvent.TIMER, this.recalcWinStep);
		}
		
		private function initController():void
		{
			this.winsArray = new Array();
			this.sublineArray = new Array();
			this.linesArray = new Array();
			this.boxesArray = new Array();
			this.holesArray = new Array();
			this.animsArray = new Array();
			this.wheelArray = new Array();
			//BUILD
			for(i=1; i<=Logic.reelLines; i++) //lines;
			{
				this.sublineArray.push(this.reelBoxes['s'+i]);
				this.linesArray.push(this['line'+i]);
			}
			for(i=1;i<6;i++)
			{
				this.holesArray.push(this.reelBoxes['h'+i]); //antimask for win symbol
				
				var wheel = new Wheel();	//add wheels
				wheel.x = this['wheel'+i].x;
				wheel.y = this['wheel'+i].y;
				this.addChildAt(wheel,this.getChildIndex(this['wheel'+i]));
				this.removeChild(this['wheel'+i]);
				this.wheelArray.push(wheel);
				
				this.boxesArray.push(this.reelBoxes['b'+((i-1)*3 + 0)]);
				this.boxesArray.push(this.reelBoxes['b'+((i-1)*3 + 1)]);
				this.boxesArray.push(this.reelBoxes['b'+((i-1)*3 + 2)]);
				//#1
				var anim = new WAnim();
				for(j=0;j<Logic.animClipsSymbols.length;j++)
				{
					anim.addFromLib(Logic.animClipsSymbols[j][1],Logic.animClipsSymbols[j][0]);
				}
				anim.y = this.reelAnims['s'+((i-1)*3 + 0)].y;
				anim.x = this.reelAnims['s'+((i-1)*3 + 0)].x;
				this.animsArray.push(anim);
				this.reelAnims.removeChild(this.reelAnims['s'+((i-1)*3 + 0)]);
				this.reelAnims.addChild(anim);
				//#2
				anim = new WAnim();
				for(j=0;j<Logic.animClipsSymbols.length;j++)
				{
					anim.addFromLib(Logic.animClipsSymbols[j][1],Logic.animClipsSymbols[j][0]);
				}
				anim.y = this.reelAnims['s'+((i-1)*3 + 1)].y;
				anim.x = this.reelAnims['s'+((i-1)*3 + 1)].x;
				this.animsArray.push(anim);
				this.reelAnims.removeChild(this.reelAnims['s'+((i-1)*3 + 1)]);
				this.reelAnims.addChild(anim);
				//#3
				anim = new WAnim();
				for(j=0;j<Logic.animClipsSymbols.length;j++)
				{
					anim.addFromLib(Logic.animClipsSymbols[j][1],Logic.animClipsSymbols[j][0]);
				}
				anim.y = this.reelAnims['s'+((i-1)*3 + 2)].y;
				anim.x = this.reelAnims['s'+((i-1)*3 + 2)].x;
				this.animsArray.push(anim);
				this.reelAnims.removeChild(this.reelAnims['s'+((i-1)*3 + 2)]);
				this.reelAnims.addChild(anim);
				
			}
			//BUILD END
			//USERDATA FROM
			this.player_bet = Logic.reelBets[0];
			this.player_balance = parent.gameInfo.balance;
			this.player_win = 0;
			this.player_lines = 1;
			
		}
		
		private function initNetwork():void
		{
			this.net_main = new Network();
			this.net_free = new Network();
		}
		
		private function initButtons():void
		{
			this.bt_spin.onMouseRelease = this.btnEventSpin; //SET LISTENER
			this.bt_spin.keys = [32]; //SETUP KEYBOARD
			
			this.bt_max.onMouseRelease = this.btnEventBetMax;
			
			this.bt_lines_next.onMouseRelease = this.btnEventLinesUp;
			this.bt_lines_prev.onMouseRelease = this.btnEventLinesDown;
			
			this.bt_bet_next.onMouseRelease = this.btnEventBetUp;
			this.bt_bet_prev.onMouseRelease = this.btnEventBetDown;
			
			this.freeResultTable.free_back.onMouseRelease = this.freeGameFinished;
			this.freeResultTable.free_back.setActive(false);
		}
		
		
		/** NETWORK EVENTS **/
		private function netSuccess(e):void
		{
			this.playNumbers = e.symbols;
			var n:Number=2;
			for(i=0;i<5;i++)
			{
				n += Math.random();
				this.wheelArray[i].current = [this.playNumbers[(i*3+0)],this.playNumbers[(i*3+1)],this.playNumbers[(i*3+2)]];
				TweenMax.delayedCall(n,this.wheelArray[i].stopWheel);
			}
			
		}

		
		private function networkError(e):void
		{
			//TODO: show alert;
			trace(e);
		}
		/** NETWORK EVENTS END **/
		
		
		

		

		
		/** ANIMATIONS **/
		
		//NEW
		public function animBlinkLines(times:int, onFinish:Function = null):void
		{
			var blinkLines = Array();
			for(i=0; i<this.winsArray.length; i++)
			{
				if(this.winsArray[i][0] > 0)
				{
					blinkLines.push(this.linesArray[(this.winsArray[i][0]-1)].s1);
					this.linesArray[(this.winsArray[i][0]-1)].s1.visible = true;
				}
			}
			if(blinkLines.length > 0)
			{
				this.anim_lines_arr = TweenMax.allTo(blinkLines, .1,{alpha:.1, yoyo:true, repeat: times}, 0, onFinish);
			} else {
				if(onFinish)
					onFinish();
			}
		}
		
		public function animBlinkLinesDestroy():void
		{
			if(this.anim_lines_arr)
			{
				for(i=0;i<this.anim_lines_arr.length;i++)
				{
					try{ this.anim_lines_arr[i].kill(); } catch(e:Error){}
				}
			}
			this.showSelectedLines();
		}
		
		public function animExplainWins( ):void
		{
			this.animBlinkLinesDestroy();
			this.anim_explain_current = -1;
			this._animWinStep();
		}
		
		public var _animExplainWinsComplete:Function;
		
		public function animStop():void
		{
			this.hideAllSublines();
			this.hideAllBoxes();
			this.stopAnimations();
			if(this.anim_explain_twm)
			{
				this.anim_explain_twm.kill();
			}
			this.animBlinkLinesDestroy()
		}
		
		private function _animWinStep():void
		{
			this.anim_explain_current ++;
			if(this.anim_explain_current == this.winsArray.length)
			{
				if(this._animExplainWinsComplete)
				{
					this._animExplainWinsComplete();
					return;
				} else {
					this.hideAllSublines();
					this.hideAllBoxes();
					this.stopAnimations();
					return;
				}
			}
			if(this.winsArray[this.anim_explain_current][0] > 0)
			{
				this._animWinLine(this.winsArray[this.anim_explain_current],this.winsArray[this.anim_explain_current][3]);
			} else {
				this._animWinSymbol(this.winsArray[this.anim_explain_current]);
			}
		}
		
		private function _animWinSymbol(line:Array):void
		{
			
		}
		
		private function _animWinSymbolComplete():void
		{
			this.hideAllSublines();
			this.hideAllBoxes();
			this.stopAnimations();
			
			this._animWinStep();
		}
		
		//WORK
		private function _animWinLine(line:Array,time:Number = 3,onFinish:Function = null):void
		{
			if(this.anim_explain_twm)
			{
				this.anim_explain_twm.kill();
			}

			this.hideAllSublines();
			this.hideAllBoxes();
			this.stopAnimations();
			this.applyBoxesColor(Logic.lineColors[line[0]]);

			for(i=4;i<line.length;i++)
			{
				this.boxesArray[(line[i])].visible = true;
				this.holesArray[(Math.floor(line[i] / 3)+1)].x = this.boxesArray[(line[i])].x;
				this.holesArray[(Math.floor(line[i] / 3)+1)].y = this.boxesArray[(line[i])].y;
				if(Logic.winAnimSymbols[this.playNumbers[line[i]]-1][0] > 0)
				{
					trace(Logic.winAnimSymbols[this.playNumbers[line[i]]-1][1]);
					this.animsArray[line[i]].startAnimByName(Logic.winAnimSymbols[this.playNumbers[line[i]]-1][1]); 
				}
			}
			this.sublineArray[(line[0]-1)].visible = true;

			//Blink it all
			this.reelBoxes.visible = true;
			
			var blinks:int = Math.ceil(time/.2);
			if(onFinish)
				this._animWinLineCompleteFunc = onFinish;
			else
				this._animWinLineCompleteFunc = this._animWinLineComplete;

			this.anim_explain_twm = TweenMax.to(this.reelBoxes, .2, {alpha:0, repeat:blinks, yoyo:true, onComplete:this._animWinLineCompleteFunc});
		}
		
		private var _animWinLineCompleteFunc:Function;
		
		private function _animWinLineComplete():void
		{
			this.hideAllSublines();
			this.hideAllBoxes();
			this.stopAnimations();
			
			this._animWinStep();
		}
		
		//WINNING ANIMATION END;
		
		
		
		
		
		
		/** NORMAL GAME **/
		public function normalGameStart():void
		{
			this.recalcWinStop();
			this.recalcWinAmount((this.player_bet*this.player_lines*-1),1000,true,false);
			this.animStop();
			this.showSelectedLines();
			this.updateUI();
			this.disableButtons();
			
			for(i=0;i<5;i++)
			{
				this.wheelArray[i].playWheel(0, null, null, null, this.normalGameResults);
			}
			this.sn_wheels1.Play(100,70);
			
			var snd:Object = 
			{
				'action':'spin',
				'lines':this.player_lines,
				'bet':this.player_bet
			};
			this.currentGameWheels = 6;
			this.net_main.sendRequest(snd, this.normalGameResults, this.networkError);
		}
		
		private function normalGameResults(obj = null):void
		{
			if(obj)
			{
				this.playNumbers = obj.symbols;
				this.currentGameWheels--;
				n = 0;
				for(i=0;i<5;i++)
				{
					n += Math.floor(Math.random()*1000);
					this.wheelArray[i].current = [this.playNumbers[(i*3+0)],this.playNumbers[(i*3+1)],this.playNumbers[(i*3+2)]];
					this.wheelArray[i].stopWheel(n);
				}
			} else {
				currentGameWheels--;
				this.sn_wheel_stop.Play(0,290);
			}
			
			if(currentGameWheels <= 0)
			{
				this.sn_wheels1.Stop();
				//TODO:Show Results;
				
				this.winsArray = Logic.calculateWins(this.player_lines, this.playNumbers);
				
				if(this.winsArray.length > 0)
				{
					//WE WON;
					var wontype:int = 0;
					var wonamnt:Number = 0;
					
					for(i=0;i<this.winsArray.length;i++)
					{
						wonamnt += this.winsArray[i][2];
						switch(this.winsArray[i][1])
						{
							case 1:
								wontype = 1;
							break;
							case 2:
								wontype = 2;
							break;
						}
					}
					if(wonamnt)
					{
						this.recalcWinAmount(wonamnt);
					}
					
					//BRANCH
					switch(wontype)
					{
						case 1:
							//FREE GAME
							for(i=0;i<this.winsArray.length;i++)
							{
								if(this.winsArray[i][1] == 1)
								{
									if(this.winsArray[i][0] > 0)
									{
										this._animWinLine(this.winsArray[i],this.winsArray[i][3],this.freeGameStart);
									} else {
										this._animWinSymbol(this.winsArray[i],this.winsArray[i][3],this.freeGameStart);
									}
									//TODO:calc amount
									this.freeSpinsCount = 10;
									
									break;
								}
							}
							//freeSpins sound
						break;
						case 2:
						
						break;
						default:
							if(wonamnt)
								this.sn_win.Play();
							this.animBlinkLines(30, this.animExplainWins);
							this.enableButtons();
						break;
					}
					
					return;
				}
				//NOTHING HAPPENED. NORMAL GAME STOPPED WITHOUT WIN.
				this.enableButtons();
			}
		}
		
		
		/** FREEE **/
		public function freeGameStart():void
		{
			trace("freeGameStart");
			this.recalcWinStop();
			this.animStop();
			
			this.freeWinSumm = 0;
			this.inOnFree = true;
			
			//TODO: calc free games count;
			
			this.logo_free.spins.text = this.freeSpinsCount;
			this.uiShowLogoFree();
			
			for(i=0;i<5;i++)
			{
				this.wheelArray[i].playWheel(0, null, null, null, this.freeGameResults);
			}
			this.sn_wheels2.Play(100,70);
			
			var snd:Object = 
			{
				'action':'free',
				'lines':this.player_lines,
				'bet':this.player_bet
			};
			this.currentGameWheels = 6;
			this.net_free.sendRequest(snd, this.freeGameResults, this.networkError);
		}
		
		public function freeGameResults(obj:Object = null):void
		{
			if(obj)
			{
				this.playNumbers = obj.symbols;
				this.currentGameWheels--;
				n = 0;
				for(i=0;i<5;i++)
				{
					n += Math.floor(Math.random()*1000);
					this.wheelArray[i].current = [this.playNumbers[(i*3+0)],this.playNumbers[(i*3+1)],this.playNumbers[(i*3+2)]];
					this.wheelArray[i].stopWheel(n);
				}
			} else {
				currentGameWheels--;
				this.sn_wheel_stop.Play(0,290);
			}
			if(currentGameWheels <= 0)
			{
				this.sn_wheels2.Stop();
				//TODO:Show Results;
				
				this.winsArray = Logic.calculateWins(this.player_lines, this.playNumbers);
				
				if(this.winsArray.length > 0)
				{
					//WE WON;
					var wontype:int = 0;
					var wonamnt:Number = 0;
					
					for(i=0;i<this.winsArray.length;i++)
					{
						wonamnt += this.winsArray[i][2];
						switch(this.winsArray[i][1])
						{
							case 12:
								wontype = 1;
							break;
							case 22:
								wontype = 2;
							break;
						}
					}
					if(wonamnt)
					{
						this.recalcWinAmount(wonamnt);
					}
					
					//BRANCH
					switch(wontype)
					{
						case 1:
							//FREE GAME
							for(i=0;i<this.winsArray.length;i++)
							{
								if(this.winsArray[i][1] == 1)
								{
									//TODO: increase free spins;
									if(this.winsArray[i][0] > 0)
									{
										this._animWinLine(this.winsArray[i],this.winsArray[i][3],this.freeGameNext);
									} else {
										this._animWinSymbol(this.winsArray[i],this.winsArray[i][3],this.freeGameNext);
									}
									break;
								}
							}
							//freeSpins sound
						break;
						case 2:
							//pauseFreeGame;
						break;
						default:
							if(wonamnt)
								this.sn_win.Play();
							this.animBlinkLines(30, this.freeGameNext);
							return;
						break;
					}
					return;
				}
				//NOTHING HAPPENED. NORMAL GAME STOPPED WITHOUT WIN.
				this.freeGameNext();
			}
		}
		
		public function freeGameNext():void
		{
			this.freeSpinsCount--;
			if(this.freeSpinsCount==0)
			{
				//CLOSE GAME;
				this.recalcWinStop();
				this.animStop();
				
				this.freeWinSumm = 0;
				this.inOnFree = false;
				this.uiShowLogoMain();
				//Show Results
				this.freeResultTable.x = 0;
				this.freeResultTable.free_back.setActive(true);
				
				return;
			}
			this.freeGameStart();
		}
		
		public function freeGameFinished(ref=null):void
		{
			this.inOnFree = false;
			trace(this.freeWinSumm);
			this.freeResultTable.x = -800;
			this.enableButtons();
		}
		

		
		/** UI **/
		public function recalcWinAmount(amount:Number, times:int = 2000, bal:Boolean = true, win:Boolean = true):void
		{
			this.recalc_time = times;
			this.recalc_balance = this.player_balance;
			this.recalc_amount = amount;
			this.recalc_start = getTimer();
			this.recalc_b = bal;
			this.recalc_w = win;
			recalc_timer.stop();
			recalc_timer.start();
		}
		
		public function recalcWinStep(e:TimerEvent):void
		{
			var proc:Number = ((getTimer()-this.recalc_start)/this.recalc_time);
			var diff:Number = proc*recalc_amount;
			if(this.recalc_b)
				this.tx_balance.text = Helper.moneyFormat(this.recalc_balance+diff);
			if(this.recalc_w)
				this.tx_win.text = Helper.moneyFormat(diff);
			if(proc>=1) this.recalcWinStop();
			delete(proc);
			delete(diff);
		}
		
		public function recalcWinStop():void
		{
			this.recalc_timer.stop();
			if(this.recalc_b)
				this.tx_balance.text = Helper.moneyFormat(this.recalc_balance+this.recalc_amount);
			if(this.recalc_w)
				this.tx_win.text = Helper.moneyFormat(this.recalc_amount);
		}
		
		public function uiShowLogoMain():void
		{
			TweenMax.to(this.logo_free,1,{alpha:0});
			TweenMax.to(this.logo_main,1,{alpha:1});
		}
		
		public function uiShowLogoFree():void
		{
			TweenMax.to(this.logo_free,1,{alpha:1});
			TweenMax.to(this.logo_main,1,{alpha:0});
		}
		
		public function updateUI():void
		{
			this.tx_balance.text = Helper.moneyFormat(this.player_balance);
			this.tx_bet_amount.text = Helper.moneyFormat(this.player_bet);
			this.tx_lines.text = this.player_lines;
			this.tx_bet_total.text = Helper.moneyFormat(this.player_bet * this.player_lines);
			this.tx_win.text = Helper.moneyFormat(this.player_win);
		}
		/** UI END **/
		
		/** BUTTONS **/
		public function enableButtons():void
		{
			this.bt_bet_next.setActive(true);
			this.bt_bet_prev.setActive(true);
			this.bt_lines_next.setActive(true);
			this.bt_lines_prev.setActive(true);
			this.bt_max.setActive(true);
			this.bt_spin.setActive(true);
			this.bt_pay.setActive(true);
		}
		public function disableButtons():void
		{
			this.bt_bet_next.setActive(false);
			this.bt_bet_prev.setActive(false);
			this.bt_lines_next.setActive(false);
			this.bt_lines_prev.setActive(false);
			this.bt_max.setActive(false);
			this.bt_spin.setActive(false);
			this.bt_pay.setActive(false);
		}
		
		/**BUTTONS EVENTS**/
		//IN_USE
		public function btnEventLinesUp(ref = null):void
		{
			this.recalcWinStop();
			this.animStop();
			this.player_lines++;
			if(this.player_lines > Logic.reelLines)
			{
				this.player_lines = 1;
				this.sn_down.Play(0,0,false);
			} else 
			{
				this.sn_up.Play(0,0,false);
			}
			this.makeLineSelect();
			this.updateUI();
		}
		//IN_USE
		public function btnEventLinesDown(ref = null):void
		{
			this.recalcWinStop();
			this.animStop();
			this.player_lines--;
			if(this.player_lines < 1)
			{
				this.player_lines = Logic.reelLines;
				this.sn_up.Play(0,0,false);
			} else {
				this.sn_down.Play(0,0,false);
			}
			this.makeLineSelect();
			this.updateUI();
		}
		//IN_USE
		public function btnEventBetUp(ref = null):void
		{
			this.recalcWinStop();
			this.animStop();
			var bet_no = Logic.reelBets.indexOf(this.player_bet);
			bet_no++;
			if(bet_no >= Logic.reelBets.length)
			{
				bet_no = 0;
				this.sn_down.Play(0,0,false);
			} else {
				this.sn_up.Play(0,0,false);
			}
			this.player_bet = Logic.reelBets[bet_no];
			this.updateUI();
		}
		//IN_USE
		public function btnEventBetDown(ref = null):void
		{
			this.recalcWinStop();
			this.animStop();
			var bet_no = Logic.reelBets.indexOf(this.player_bet);
			bet_no--;
			if(bet_no < 0)
			{
				bet_no = Logic.reelBets.length-1;
				this.sn_up.Play(0,0,false);
			} else {
				this.sn_down.Play(0,0,false);
			}
			this.player_bet = Logic.reelBets[bet_no];
			this.updateUI();
		}
		//UNTESTED
		public function btnEventBetMax(ref = null):void
		{
			this.animStop();
			this.player_lines = Logic.reelLines;
			this.showSelectedLines();
			
			this.updateUI();
			
			var snd:XSound = new sndSpinPress();
			snd.Play(0,60);
			//disable check;
			this.gameStart();
		}
		//UNTESTED
		public function btnEventSpin(ref = null):void
		{
			this.recalcWinStop();
			this.animStop();
			this.updateUI();

			
			var snd:XSound = new sndSpinPress();
			snd.Play(0,60);
			//disable check;
			this.normalGameStart();
		}
		
		/** BUTTONS END **/
		
		/** LINES **/	
		//IN_USE
		public function makeLineSelect():void
		{
			for(i=0;i<Logic.reelLines;i++)
			{
				this.linesArray[i].s3.visible = (this.player_lines > i) ? true :false;
				this.linesArray[i].s2.visible = (this.player_lines > i) ? false :true;
				this.linesArray[i].s1.visible = (this.player_lines > i) ? true :false;
				this.linesArray[i].s1.alpha = 1;
			}
		}
		//IN_USE
		public function showSelectedLines():void
		{
			for(i=0;i<Logic.reelLines;i++)
			{
				this.linesArray[i].s3.visible = (this.player_lines > i) ? true :false;
				this.linesArray[i].s2.visible = (this.player_lines > i) ? false :true;
				this.linesArray[i].s1.visible = false;
				this.linesArray[i].s1.alpha = 1;
			}
		}
		/** LINES END **/
		
		//-------------------------------------------------------------------------------------------------------
		public function deinitWinAnim():void
		{
			this.hideAllSublines();
			this.hideAllBoxes();
			//stop all anims
		}
		
		
		//IN_USE
		public function applyBoxesColor(color:Number):void
		{
			var tint:Color = new Color();
			tint.setTint(color, 1);
			this.reelBoxes.transform.colorTransform = tint;
		}
		//IN_USE
		public function hideAllSublines():void
		{
			var i:int;
			for(i=1;i<6;i++)
			{
				this.holesArray[i-1].y = -500;
			}
			for(i=0;i<Logic.reelLines;i++)
			{
				this.sublineArray[i].visible = false;
			}
		}
		//IN_USE
		public function hideAllBoxes():void
		{
			for(var k=0;k<15;k++)
			{
				this.boxesArray[k].visible = false;
			}
		}
		//IN_USE
		public function stopAnimations():void
		{
			for(var k=0;k<15;k++)
			{
				this.animsArray[k].hideAll();
			}
		}
		//-------------------------------------------------------------------------------------------------------
	}
	
}
